let did = 0;
class Dep {
  constructor() {
    this.subs = [];
    this.id = did++;
  }
  depend() {
    if (Dep.target) {
      Dep.target.addDep(this);
    }
  }
  addSub(watcher) {
    this.subs.push(watcher);
  }
  notify() {
    let subs = this.subs.slice();
    for (let index = 0; index < subs.length; index++) {
      subs[index].update();
    }
  }
}
let stack = [];
Dep.target = null;
function pushTarget(watcher) {
  Dep.target = watcher;
  stack.push(watcher);
}

function popTarget() {
  stack.pop();
  Dep.target = stack[stack.length - 1];
}
